﻿using System;
using System.Linq;
using System.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DLinkedList;

namespace UnitTestDLinkedList
{
    [TestClass]
    public class UnitTest1
    {


        [TestMethod]
        public void TestMethodEmpty()
        {
            ForwardList<int> fli = new ForwardList<int>();

            Assert.AreEqual(true, fli.IsEmpty());
        }

        [TestMethod]
        public void TestMethodCount()
        {
            ForwardList<int> fli = new ForwardList<int>();

            Assert.AreEqual(0, fli.Count());
        }

        [TestMethod]
        public void TestMethodFirst_AddFirst()
        {
            ForwardList<int> fli = new ForwardList<int>();
            fli.AddFirst(10);
            Assert.AreEqual(10, fli.First.value);
            fli.AddFirst(20);
            Assert.AreEqual(20, fli.First.value);
            fli.AddFirst(30);
            Assert.AreEqual(30, fli.First.value);
        }

        [TestMethod]
        public void TestMethodLast_AddLast()
        {
            ForwardList<int> fli = new ForwardList<int>();
            fli.AddFirst(10);
            Assert.AreEqual(10, fli.Last.value);
            fli.AddFirst(20);
            Assert.AreEqual(10, fli.Last.value);
            fli.AddLast(40);
            Assert.AreEqual(40, fli.Last.value);
            fli.AddLast(50);
            Assert.AreEqual(50, fli.Last.value);
        }

        [TestMethod]
        public void TestMethodClear()
        {
            ForwardList<int> fli = new ForwardList<int>();
            fli.AddFirst(10);
            fli.AddFirst(20);
            Assert.AreEqual(2, fli.Count);
            fli.Clear();
            Assert.AreEqual(0, fli.Count);
            
        }

        [TestMethod]
        public void TestMethodContains()
        {
            ForwardList<int> fli = new ForwardList<int>();
            fli.AddFirst(10);
            fli.AddFirst(20);
            Assert.AreEqual(true, fli.Contains(10));
            Assert.AreEqual(true, fli.Contains(20));
            Assert.AreEqual(false, fli.Contains(30));
        }

        [TestMethod]
        public void TestMethodFind()
        {
            ForwardList<int> fli = new ForwardList<int>();
            fli.AddFirst(10);
            fli.AddFirst(20);
            Assert.AreEqual(10, fli.Find(10));
            Assert.AreEqual(20, fli.Find(20));
            Assert.AreEqual(default(int), fli.Find(30));
        }

        [TestMethod]
        public void TestMethodRemove()
        {
            ForwardList<int> fli = new ForwardList<int>();
            fli.AddFirst(10);
            fli.AddFirst(20);
            fli.AddFirst(30);
            Assert.AreEqual(true, fli.Contains(10));
            Assert.AreEqual(true, fli.Contains(20));
            Assert.AreEqual(true, fli.Contains(30));
            fli.Remove(20);
            Assert.AreEqual(false, fli.Contains(20));
            fli.Remove(10);
            Assert.AreEqual(false, fli.Contains(10));
            fli.Remove(30);
            Assert.AreEqual(false, fli.Contains(30));
            Assert.AreEqual(0, fli.Count);
        }

        
        [TestMethod]
        public void TestMethodRemoveLast()
        {
            ForwardList<int> fli = new ForwardList<int>();
            fli.AddFirst(10);
            fli.AddFirst(20);
            fli.AddFirst(30);
            Assert.AreEqual(true, fli.Contains(10));
            Assert.AreEqual(true, fli.Contains(20));
            Assert.AreEqual(true, fli.Contains(30));
            fli.RemoveLast();
            Assert.AreEqual(false, fli.Contains(10));
            Assert.AreEqual(20, fli.Last.value);
            fli.RemoveLast();
            Assert.AreEqual(false, fli.Contains(20));
            Assert.AreEqual(30, fli.Last.value);
            fli.RemoveLast();
            Assert.AreEqual(false, fli.Contains(30));
            Assert.AreEqual(0, fli.Count);
        }

        [TestMethod]
        public void TestMethodRemoveFirst()
        {
            ForwardList<int> fli = new ForwardList<int>();
            fli.AddFirst(10);
            fli.AddFirst(20);
            fli.AddFirst(30);
            Assert.AreEqual(true, fli.Contains(10));
            Assert.AreEqual(true, fli.Contains(20));
            Assert.AreEqual(true, fli.Contains(30));
            fli.RemoveFirst();
            Assert.AreEqual(false, fli.Contains(30));
            Assert.AreEqual(20, fli.First.value);
            fli.RemoveFirst();
            Assert.AreEqual(false, fli.Contains(20));
            Assert.AreEqual(10, fli.First.value);
            fli.RemoveFirst();
            Assert.AreEqual(false, fli.Contains(10));
            Assert.AreEqual(0, fli.Count);
        }


    }
}
